package com.example.service.impl;

import com.example.entity.Users;
import com.example.dao.UsersDao;
import com.example.service.UsersService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * (Users)表服务实现类
 *
 * @author makejava
 * @since 2022-04-20 15:51:04
 */
@Service("usersService")
public class UsersServiceImpl implements UsersService {
    @Resource
    private UsersDao usersDao;

    @Override
    public Users queryById(Integer uid) {
        Users users = usersDao.queryById(uid);
        return  users;
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<Users> queryAllByLimit(int offset, int limit) {
        return this.usersDao.queryAllByLimit(offset, limit);
    }

    @Override
    public PageInfo<Users> queryAllByPage(Users users, Integer pageNum, Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Users> userList = usersDao.queryAll(users);
        PageInfo<Users> userListPage = new PageInfo<>(userList);
        return userListPage;
    }

    /**
     * 新增数据
     *
     * @param users 实例对象
     * @return 实例对象
     */
    @Override
    public Users insert(Users users) {
        this.usersDao.insert(users);
        return users;
    }

    /**
     * 修改数据
     *
     * @param users 实例对象
     * @return 实例对象
     */
    @Override
    public Users update(Users users) {
        this.usersDao.update(users);
        return users;
    }

    /**
     * 通过主键删除数据
     *
     * @param uid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer uid) {
        boolean flag = this.usersDao.deleteById(uid) > 0;
        return flag;
    }
}
